<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Felicalib Applet JNLP</title>
<link rel="stylesheet" href="css/cf.css">
<!-- Google hosting Jquery  http://blog.fkoji.com/2009/01142136.html-->
<script
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"
	type="text/javascript"></script>
<script src="js/cf.js" type="text/javascript"></script>
<script src="js/lib/jquery.cookie.js" type="text/javascript"></script>
<!-- Google Analytics-->
<script type="text/javascript">
	var _gaq = _gaq || [];
	_gaq.push([ '_setAccount', 'UA-26742354-1' ]);
	_gaq.push([ '_trackPageview' ]);

	(function() {
		var ga = document.createElement('script');
		ga.type = 'text/javascript';
		ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl'
				: 'http://www')
				+ '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(ga, s);
	})();
</script>
<!-- PLus One-->
<script type="text/javascript">
	(function() {
		var po = document.createElement('script');
		po.type = 'text/javascript';
		po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(po, s);
	})();
</script>
<!-- メインスクリプト-->
<script type="text/javascript">
	var applet = null;
	var errflg = false;
	var sender = new cf();
	var timer = false;
	var timer_id = null;
	var idm = null;
	function appletReader(loadLimit) {
		try {
			applet = document.felicaHeadlessApplet;
			applet.getAppletName();
			errflg = false;
		} catch (err) {
			errflg = true;
		}
		if (errflg) {
			if (loadLimit <= 0)
				return;
			loadLimit--;
			window.setTimeout(appletReader, 1000, loadLimit);
		} else {
		}
	}

	appletReader(15);

	function buyCuffee() {
		appletReader(1);
		idm = applet.getIDm();
		if (!idm) {
			alert("カードからＩＤが読み取れません。");
			return;
		}
		ret = confirm("チケットを1枚使ってコーヒーを購入します。");
		if (!ret)
			return;
		sender.send(idm);
	}

	function StartPolling() {
		if (timer == false) {
			timer_id = setTimeout(function() {
				timer = true;
				buyCuffee();
			}, 2000);
			return;
		}
		alert("start polling!");
	}
	function StopPolling() {
		if (timer_id != null) {
			clearTimeout(timer_id);
			alert("stop polling!");
		}
	}
</script>
</head>
<body>
	<div>
		<g:plusone annotation="inline"></g:plusone>
	</div>
	<div class="title">Buy a cup of Cofee?</div>
	<div>
		<button class="btn" onclick='StartPolling();'>StartPolling!</button>
		<button class="btn" onclick='StopPolling();'>StopPolling!</button>
	</div>
	<!--<button class="btn" onclick='getPMM();'>PMM取得</button>-->
	<br />
	<div id="idTray"></div>
	<div id="resultTray"></div>
	<applet alt="Headless Applet" name="felicaHeadlessApplet"
		code="com.googlecode.felicalib.sample.applet.FelicaHeadlessApplet"
		width="1" height="1">
		<param name="draggable" value="true">
		<param name="jnlp_href" value="FelicalibSampleApplet.jnlp">
	</applet>
</body>
</html>